package com.sds.prolog.model;

import com.google.common.collect.Sets;
import com.sds.system.models.IdentifiedObject;

import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.Set;

@XmlRootElement
@Entity
public class Laptop implements IdentifiedObject {
    private String id;
    private String name;
    private String url;
    private Set<String> refinedAttribute;

    public Laptop() {
        refinedAttribute = Sets.newHashSet();
    }

    @Id
    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @OneToMany(cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    public Set<String> getRefinedAttribute() {
        return refinedAttribute;
    }

    public void setRefinedAttribute(Set<String> refinedAttribute) {
        this.refinedAttribute = refinedAttribute;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        Laptop laptop = (Laptop) o;

        if (name != null ? !name.equals(laptop.name) : laptop.name != null) return false;
        if (refinedAttribute != null ? !refinedAttribute.equals(laptop.refinedAttribute) : laptop.refinedAttribute != null)
            return false;
        return !(url != null ? !url.equals(laptop.url) : laptop.url != null);

    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (url != null ? url.hashCode() : 0);
        result = 31 * result + (refinedAttribute != null ? refinedAttribute.hashCode() : 0);
        return result;
    }
}
